package view.content;

import javax.swing.JPanel;

import model.Preference;
import model.contents.Content;
import util.PlayerUtilities;

public abstract class ContentBox extends JPanel {

	Content content;
	int width;
	int height;

	public ContentBox(Content c, int width, int height) {
		this.content = c;
		this.width = width;
		this.height = height;
	}

	public static ContentBox createContentBox(Content c, int width, int height) {
		if (c == null) {
			return null;
		}
		ContentBox cb = null;
		switch (c.getType()) {
		case IMAGE:
			cb = new ImageBox(c, width, height);
			//cb = new BrowserBox(c, width, height);
			break;
		case VIDEO:
			if (Preference.getInstance().isZeroPauseTime()) {
				// don't load the video
				System.out.println("CASE: "+Preference.getInstance().isZeroPauseTime());
				
			} else if (VideoBox.isSupported()) {
				
				System.out.println("CASE: VLC Video box");
				cb = new VideoBox(c, width, height);
				//cb = new XuggleVideoBox(c, width, height);
			}
			else
			{
				cb = new XuggleVideoBox(c, width, height);
			}
			break;
		case HTML:
			//cb = new HtmlBox(c, width, height);
			if(PlayerUtilities.isBrowserSupported())
			{
				cb = new BrowserBox(c, width, height);
			}
			else
			{
				cb = new HtmlBox(c, width, height);
			}
			break;
		case GIF:
			break;
		case TEXT:
			cb = new TextBox(c, width, height);
			break;
		case TABLE:
			cb = new TableBox(c, width, height);
			break;
		case REALESTATE_LISTING:
			cb = new RealEstateListingBox(c, width, height);
			break;
		case WEATHER:
			System.out.println("Inside case statement = "+c.getType());
			cb = new WeatherBox(c, width, height);
			break;
		case BROWSER:
			///System.out.println("Inside case statement = "+c.getType());
			if(PlayerUtilities.isBrowserSupported())
			{
				//cb = new BrowserBox(c, width, height);
			}
			break;	
		case MIXED:
			break;
		}
		return cb;
	}

	public Content getContent() {
		return this.content;
	}

	@Override
	public int getWidth() {
		return this.width;
	}

	@Override
	public int getHeight() {
		return this.height;
	}

	public void play() {
	}

	public void cleanup() {
	}
}
